package cn.edu.usts;

import cn.edu.usts.pojo.User;
import cn.edu.usts.service.UserService;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;

public class Client {
    public static void main(String[] args) throws MalformedURLException {
       System.setProperty("javax.xml.bind.JAXBContext", "com.sun.xml.internal.bind.v2.ContextFactory");
        //创建WSDL的URL
        URL url = new URL("http://localhost:8080/ws/api?wsdl");
        // 指定命名空间和服务名称
        QName qName = new QName("http://service.sbmpservice.usts.edu.cn", "UserService");
        Service service = Service.create(url, qName);
        // 通过getPort方法返回指定接口
        UserService myServer = service.getPort(UserService.class);  // 方法1
//        UserService myServer = service.getPort(new QName("http://serviceImpl.service.usts.edu.cn/", "UserServiceImplPort"), UserService.class); // 方法2

        // 调用方法 获取返回值
        User user1 = new User(2,"tom");
        myServer.addUser(user1);
        User user = myServer.queryUser(2);
        System.out.println(user.toString());
    }

}
